<!doctype html>
<html lang="en">
<head>
    <title>Code coverage report for javascripts/reduxUtils.js</title>
    <meta charset="utf-8" />
    <link rel="stylesheet" href="../prettify.css" />
    <link rel="stylesheet" href="../base.css" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style type='text/css'>
        .coverage-summary .sorter {
            background-image: url(../sort-arrow-sprite.png);
        }
    </style>
</head>
<body>
<div class='wrapper'>
  <div class='pad1'>
    <h1>
      <a href="../index.html">All files</a> / <a href="index.html">javascripts</a> reduxUtils.js
    </h1>
    <div class='clearfix'>
      <div class='fl pad1y space-right2'>
        <span class="strong">47.54% </span>
        <span class="quiet">Statements</span>
        <span class='fraction'>29/61</span>
      </div>
      <div class='fl pad1y space-right2'>
        <span class="strong">18.18% </span>
        <span class="quiet">Branches</span>
        <span class='fraction'>8/44</span>
      </div>
      <div class='fl pad1y space-right2'>
        <span class="strong">58.33% </span>
        <span class="quiet">Functions</span>
        <span class='fraction'>7/12</span>
      </div>
      <div class='fl pad1y space-right2'>
        <span class="strong">47.54% </span>
        <span class="quiet">Lines</span>
        <span class='fraction'>29/61</span>
      </div>
    </div>
  </div>
  <div class='status-line low'></div>
<pre><table class="coverage">
<tr><td class="line-count quiet">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115</td><td class="line-coverage quiet"><span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">3x</span>
<span class="cline-any cline-yes">3x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">3x</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">3x</span>
<span class="cline-any cline-yes">3x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">13x</span>
<span class="cline-any cline-yes">13x</span>
<span class="cline-any cline-yes">13x</span>
<span class="cline-any cline-yes">20x</span>
<span class="cline-any cline-yes">10x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">10x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">13x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">3x</span>
<span class="cline-any cline-yes">3x</span>
<span class="cline-any cline-yes">3x</span>
<span class="cline-any cline-yes">4x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">3x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">16x</span>
<span class="cline-any cline-yes">16x</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">16x</span>
<span class="cline-any cline-yes">16x</span>
<span class="cline-any cline-yes">16x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span></td><td class="text"><pre class="prettyprint lang-js">import shortid from 'shortid';
import { compose } from 'redux';
import persistState from 'redux-localstorage';
&nbsp;
export function addToObject(state, arrKey, obj) {
  const newObject = Object.assign({}, state[arrKey]);
  const copiedObject = Object.assign({}, obj);
&nbsp;
  <span class="missing-if-branch" title="if path not taken" >I</span>if (!copiedObject.id) {
<span class="cstat-no" title="statement not covered" >    copiedObject.id = shortid.generate();</span>
  }
  newObject[copiedObject.id] = copiedObject;
  return Object.assign({}, state, { [arrKey]: newObject });
}
&nbsp;
export function alterInObject(state, arrKey, obj, alterations) {
  const newObject = Object.assign({}, state[arrKey]);
  newObject[obj.id] = Object.assign({}, newObject[obj.id], alterations);
  return Object.assign({}, state, { [arrKey]: newObject });
}
&nbsp;
export function alterInArr(state, arrKey, obj, alterations) {
  // Finds an item in an array in the state and replaces it with a
  // new object with an altered property
  const idKey = 'id';
  const newArr = [];
  state[arrKey].forEach((arrItem) =&gt; {
    if (obj[idKey] === arrItem[idKey]) {
      newArr.push(Object.assign({}, arrItem, alterations));
    } else {
      newArr.push(arrItem);
    }
  });
  return Object.assign({}, state, { [arrKey]: newArr });
}
&nbsp;
export function removeFromArr(state, arrKey, obj, idKey = </span></span>'id') <span class="branch-1 cbranch-no" title="branch not covered" ><span class="branch-0 cbranch-no" title="branch not covered" >{
  const newArr = [];
  state[arrKey].forEach((arrItem) =&gt; {
    if (!(obj[idKey] === arrItem[idKey])) {
      newArr.push(arrItem);
    }
  });
  return Object.assign({}, state, { [arrKey]: newArr });
}
&nbsp;
export f</span>unction <span class="fstat-no" title="function not covered" >getFromArr(arr, id) {
  l</span>et <span class="cstat-no" title="statement not covered" >obj;
<span class="cstat-no" title="statement not covered" >  arr.forEach(<span class="fstat-no" title="function not covered" >(</span>o) =&gt; {</span>
<span class="cstat-no" title="statement not covered" >    if (o.id === id) {</span>
<span class="cstat-no" title="statement not covered" >      obj = o;</span>
    }
  });
<span class="cstat-no" title="statement not covered" >  return obj;</span>
}
&nbsp;
export function addToArr(state, arrKey, obj) {
  const newObj = Object.assign({}, obj);
  <span class="missing-if-branch" title="if path not taken" >I</span>if (!newObj.id) {
<span class="cstat-no" title="statement not covered" >    newObj.id = shortid.generate();</span>
  }
  const newState = {};
  newState[arrKey] = [...state[arrKey], newObj];
  return Object.assign({}, state, newState);
}
&nbsp;
export f</span>unction <span class="fstat-no" title="function not covered" >initEnhancer(persist = true) <span class="cstat-no" title="statement not covered" ></span>{
  l</span>et enhancer = <span class="cstat-no" title="statement not covered" >persist ? compose(persistState()) : compose();
<span class="cstat-no" title="statement not covered" >  if (process.env.NODE_ENV === 'dev') {</span>
    /* eslint-disable no-underscore-dangle */
    c</span>onst composeEnhancers = <span class="cstat-no" title="statement not covered" >window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
    /* eslint-enable */
<span class="cstat-no" title="statement not covered" >    enhancer = persist ? composeEnhancers(persistState()) : composeEnhancers();</span>
  }
<span class="cstat-no" title="statement not covered" >  return enhancer;</span>
}
&nbsp;
export f</span>unction <span class="fstat-no" title="function not covered" >areArraysShallowEqual(arr1, arr2) {
  // returns whether 2 arrays are shallow equal
  // used in shouldComponentUpdate when denormalizing arrays
  // where the array object is different every time, but the content might
  // be the same
<span class="cstat-no" title="statement not covered" >  if (!arr1 || !arr2) {</span>
<span class="cstat-no" title="statement not covered" >    return false;</span>
  }
<span class="cstat-no" title="statement not covered" >  if (arr1.length !== arr2.length) {</span>
<span class="cstat-no" title="statement not covered" >    return false;</span>
  }
  c</span>onst length = <span class="cstat-no" title="statement not covered" >arr1.length;
<span class="cstat-no" title="statement not covered" >  for (let i = 0; i &lt; length; i++) {</span>
<span class="cstat-no" title="statement not covered" >    if (arr1[i] !== arr2[i]) {</span>
<span class="cstat-no" title="statement not covered" >      return false;</span>
    }
  }
<span class="cstat-no" title="statement not covered" >  return true;</span>
}
&nbsp;
export f</span>unction <span class="fstat-no" title="function not covered" >areObjectsEqual(obj1, obj2) {
<span class="cstat-no" title="statement not covered" >  if (!obj1 || !obj2) {</span>
<span class="cstat-no" title="statement not covered" >    return false;</span>
  }
<span class="cstat-no" title="statement not covered" >  if (! Object.keys(obj1).length !== Object.keys(obj2).length) {</span>
<span class="cstat-no" title="statement not covered" >    return false;</span>
  }
<span class="cstat-no" title="statement not covered" >  for (const id in obj1) {</span>
<span class="cstat-no" title="statement not covered" >    if (!obj2.hasOwnProperty(id)) {</span>
<span class="cstat-no" title="statement not covered" >      return false;</span>
    }
<span class="cstat-no" title="statement not covered" >    if (obj1[id] !== obj2[id]) {</span>
<span class="cstat-no" title="statement not covered" >      return false;</span>
    }
  }
<span class="cstat-no" title="statement not covered" >  return true;</span>
}
&nbsp;</pre></td></tr>
</table></pre>
<div class='push'></div><!-- for sticky footer -->
</div><!-- /wrapper -->
<div class='footer quiet pad2 space-top1 center small'>
  Code coverage
  generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Tue Apr 11 2017 20:15:55 GMT-0700 (PDT)
</div>
</div>
<script src="../prettify.js"></script>
<script>
window.onload = function () {
        if (typeof prettyPrint === 'function') {
            prettyPrint();
        }
};
</script>
<script src="../sorter.js"></script>
</body>
</html>
